package com.ruoyi.leave.service;

import com.ruoyi.common.core.domain.AbstractFrom;
import org.activiti.api.process.model.ProcessInstance;
import org.activiti.api.process.model.builders.ProcessPayloadBuilder;
import org.activiti.api.process.runtime.ProcessRuntime;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @description: 抽象工作流
 * @author: stone
 * @date: Created by 2023/2/8 17:25
 * @version: 1.0.0
 * @pakeage: com.ruoyi.leave.service
 */
public abstract class AbstractWorkflowService<T>{
    @Autowired
    private ProcessRuntime processRuntime;

    public ProcessInstance startFlow(T t) {
        AbstractFrom from = this.buildFrom(t);

        return processRuntime.start(ProcessPayloadBuilder
                .start()
                .withProcessDefinitionKey(from.getDefinitionKey())
                .withName(from.getTitle())
                .withBusinessKey(from.getId())
                .withVariables(from.getVariable())
                .build());
    }

    public abstract AbstractFrom buildFrom(T t);


}
